const APP = getApp()

const { httpRequest, appmark, webUrl: jisAPP } = APP.jisConfig || {}

// 获取微信扫脸access_token
const getWxAccessToken = function () {
  return new Promise((resolved, rejected) => {
    wx.request({
      url: `${httpRequest}/jiswechat/getAccessToken.do`,
      data: {
        appmark
      },
      success(res) {
        if (res.data.access_token) {
          resolved(res.data.access_token || '')
        } else {
          rejected(res.data.errmsg)
        }
      },
      fail(error) {
        rejected('请求超时，请重试')
      }
    })
  })
}

// 获取微信扫脸认证结果
const getWxVertifyResult = function (access_token = "", verifyResult = "") {
  return new Promise((resolved, rejected) => {
    wx.request({
      url: `${httpRequest}/jiswechat/getInfo.do`,
      data: {
        appmark,
        params: JSON.stringify({
          access_token,
          verify_result: verifyResult
        })
      },
      success(res) {
        if (res.data && res.data.errcode == '0') {
          resolved()
        } else {
          rejected(res.data.errmsg)
        }
      },
      fail(error) {
        rejected('请求超时，请重试')
      }
    })
  })
}

module.exports = {
  jisAPP,
  getWxAccessToken,
  getWxVertifyResult
}